#pragma once

#include <vector>
#include <MyControls/ProgressDlg.h>
#include "Types.h"
#include "Renderer.h"
#include "MasksCollection.h"
#include <mswin/seq_name_factory.h>

typedef std::vector<MasksCollection> MasksCollectionVector;

class CXComp;

class MaskExporter : public Renderer
{
public:
	MaskExporter(CXComp & Comp) : Renderer(Comp) { }
	void Export();
protected:
	virtual bool ExportSmoothMasks() const = 0;
	///return false if some masks in work area were not found and export is canceled
	virtual void WriteMask(Size frame, String const & path) = 0;
	virtual bool CanSaveInTwoBitDepths() const = 0;
	virtual ~MaskExporter() { }
private: //mswin::thread interface
	virtual void run();
protected:
	bool m_bSaveInGreyscale;
	MasksCollectionVector m_Data;
private:
	bool PrepareData();
private:
	My::ProgressDlg m_Progress;
	mswin::seq_name_factory m_SeqNameFactory;
};

class CrispMaskExporter : public MaskExporter
{
public:
	CrispMaskExporter(CXComp & Comp) : MaskExporter(Comp) { }
protected:
	virtual bool ExportSmoothMasks() const { return false; }
	virtual void WriteMask(Size frame, String const & path);
	virtual bool CanSaveInTwoBitDepths() const { return true; }
	virtual ~CrispMaskExporter() { if (created()) wait_finish(); }
};

class SmoothMaskExporter : public MaskExporter
{
public:
	SmoothMaskExporter(CXComp & Comp) : MaskExporter(Comp) { }
protected:
	virtual bool ExportSmoothMasks() const { return false; }
	virtual void WriteMask(Size frame, String const & path);
	virtual bool CanSaveInTwoBitDepths() const { return false; }
	virtual ~SmoothMaskExporter() { if (created()) wait_finish(); }
};
